package com.second.app.thread.线程基础.day07.线程通信.实战.backup;

/**
 * @author gyz
 * @date 2021/1/27 17:16
 */
public class DbTools {

    volatile private boolean preIsA = false;

    private static final Integer loopCount = 5;

    synchronized public void backupA() {
        try {
            while (preIsA) {
                wait();
            }
            for (int i = 0; i < loopCount; i++) {
                System.out.println("★★★★★★★★");
            }
            preIsA = true;
            this.notifyAll();
        } catch (InterruptedException e) {
            e.printStackTrace();
        }
    }

    synchronized public void backupB() {
        try {
            while (!preIsA) {
                wait();
            }
            for (int i = 0; i < loopCount; i++) {
                System.out.println("☆☆☆☆☆☆☆☆");
            }
            preIsA = false;
            this.notifyAll();
        } catch (InterruptedException e) {
            e.printStackTrace();
        }
    }

}
